package com.lanou.utp.controller;

import com.lanou.utp.entity.ResponseData;
import com.lanou.utp.entity.Student;
import com.lanou.utp.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api("学生信息")
@RestController
public class StudentController {

    @Resource
    private StudentService studentService;


    /**
     * 获取学生列表信息
     * @param page 当前页数
     * @return
     */
    @GetMapping("school/7/students")
    public Map<String,Object> selectStudentAll(@RequestParam Integer page){
        Map<String, Object> map = studentService.selectStuAll(page);
        return map;
    }

    @PutMapping("student/{id}")
    public ResponseData updateStu(@PathVariable Integer id, @RequestBody Student student){
        ResponseData responseData = studentService.updateStu(student);
        return responseData;
    }

    @PostMapping("student")
    public ResponseData addStudnt(@RequestBody Student student){
        ResponseData responseData = studentService.addStudent(student);
        return responseData;
    }

    @DeleteMapping("student/{id}")
    public ResponseData delStudent(@PathVariable Integer id){
        ResponseData responseData = studentService.delStudent(id);
        return responseData;
    }
    @DeleteMapping("students/{id}")
    public ResponseData delStudents(@PathVariable List<Integer> id){
        ResponseData responseData = studentService.delStudents(id);
        return responseData;
    }

    @ApiOperation("根据班级id, 查询该班级的所有学生")
    @GetMapping("/clazz/student")
    public ResponseData getStudentsByClazzId (Integer id) {
        List<Student> studentList = this.studentService.getStudentsByClazzId(id);
        return new ResponseData(studentList);
    }



}
